import React from 'react'
import {Router, Route, Switch,Redirect } from 'react-router-dom'
import { Login } from '@/pages/Login/Login.js'
import {customHistory} from '@/utils/history.js'
import { GeekLayout } from '@/pages/GeekLayout/GeekLayout.js'
import { NotFound } from '@/pages/NotFound/NotFound'
import {inspectToken} from '@/utils'
import './App.scss'
export const App = () => {
  return (
    <div className='App'>
    <Router history={customHistory}>
      <Switch>
        <Route exact path="/" render={() => <Redirect to="/home" />} />
        <Route path={'/login'} component={Login}></Route>
          <Route path={'/home'} render={(props) => {
            //判断token是否存在
            if (inspectToken()) {
            return <GeekLayout />
            }
            return <Redirect to={{
              pathname: '/login',
              state: {
                from:props.location.pathname
              }
            }} />
          }}></Route>
        <Route component={NotFound}></Route>
        </Switch> 
      </Router>
      </div>
  )
}
